package com.zhku.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zhku.yygh.cmn.mapper.DictMapper;
import com.zhku.yygh.model.cmn.Dict;
import com.zhku.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @BelongsProject: yygh-parent
 * @BelongsPackage: com.zhku.yygh.cmn.listener
 * @Author: "deweyMDH"
 * @CreateTime: 2023-05-12  16:49
 * @Version: 1.0
 */
public class DictListener extends AnalysisEventListener<DictEeVo> {

    // 因为要写入数据库，所以要加mapper
    private DictMapper dictMapper;
    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    //一行一行读取,是从第二行开始读的，第一行是表头
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //调用方法添加数据库
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
